package com.legendshop.openportal.sdk.model.request.v4;

import com.legendshop.openportal.sdk.model.BaseRequest;
import com.legendshop.openportal.sdk.model.constants.ApiPathConstantsV4;
import com.legendshop.openportal.sdk.model.constants.ProdDeliveryTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * V4商品保存请求
 */
@Data
public class ProdSaveV4Request extends BaseRequest {

    private static final long serialVersionUID = 6733927157737092990L;

	@NotNull(message = "店铺ID不能为空")
	@ApiModelProperty(value = "店铺ID")
	private Long shopId;

	@ApiModelProperty("外部商品编号")
	@NotBlank(message = "外部商品编号不能为空")
	@Length(max = 100, message = "外部商品编号长度不能超过100")
	private String externalProdId;

	@NotBlank(message = "商品名称不能为空")
	@ApiModelProperty(value = "商品名称")
	private String prodName;

	@Size(max = 3, message = "商品类目最多支持三级")
	@ApiModelProperty(value = "商品类目，店铺ID对应的类目，最多支持三级，请按顺序传入")
	private List<String> cateName;

	@NotEmpty(message = "商品主图不能为空")
	@ApiModelProperty(value = "商品主图")
	@Size(min = 1, max = 6, message = "商品主图最多支持六张")
	private List<String> picList;

	@Size(max = 20, message = "商品主图最多支持20张")
	@ApiModelProperty(value = "商品详情图片，与商品详情文本二选一，优先使用详情图片")
	private List<String> detailPicList;

	@ApiModelProperty(value = "商品详情文本，支持HTML格式，与商品详情图片二选一")
	private String detailText;

	@Valid
	@ApiModelProperty("商品参数")
	private List<Attr> prodAttrList;

	@Valid
	@ApiModelProperty("sku列表")
	@NotEmpty(message = "sku列表不能为空")
	@Size(min = 1, message = "sku列表不能为空")
	private List<Sku> skuList;

	@ApiModelProperty(value = "是否强制更新，默认false")
	private Boolean forceUpdate = false;

	/**
	 * 1：到店自提2：商家快递3：到店自提&商家快递
	 */
	@NotNull(message = "配送方式不能为空")
	@ApiModelProperty(value = "配送方式 TO_STORE：到店自提 SHOP_EXPRESS：商家快递 TO_STORE_AND_SHOP_EXPRESS：到店自提&商家快递")
	private ProdDeliveryTypeEnum deliveryType;

	/**
	 * 关联的运费规则ID，当deliveryType为SHOP_EXPRESS或TO_STORE_AND_SHOP_EXPRESS时必填，与固定运费二选一，都有值时优先使用固定运费
	 */
	@ApiModelProperty(value = "运费规则ID")
	private Long transportId;

	/**
	 * 固定运费，当deliveryType为SHOP_EXPRESS或TO_STORE_AND_SHOP_EXPRESS时必填，与运费规则ID二选一，都有值时优先使用固定运费
	 */
	@ApiModelProperty(value = "固定运费")
	@DecimalMin(value = "0", message = "固定运费必须大于等于0")
	@DecimalMax(value = "99999999.99", message = "固定运费必须小于等于99999999.99")
	private BigDecimal fixedFreight;

	@Data
	@Builder
	@NoArgsConstructor
	@AllArgsConstructor
	public static class Sku implements Serializable {
		private static final long serialVersionUID = -543210987654321L;

		@NotBlank(message = "SKU名称不能为空")
		@ApiModelProperty(value = "SKU名称")
		private String skuName;

		@Valid
		@Size(max = 6, message = "规格属性列表长度小于等于6")
		@ApiModelProperty(value = " 规格属性，单规格商品可不传；多规格时，请确保各规格的规格属性长度一致，并按顺序传入（顺序默认以第一个规格的为主）")
		private List<Attr> specificationList;

		@Size(max = 6, message = "SKU主规格图最多支持六张")
		@ApiModelProperty(value = "SKU主规格图")
		private List<String> specificationPic;

		@NotNull(message = "SKU销售价不能为空")
		@ApiModelProperty(value = "SKU销售价")
		@DecimalMin(value = "0", message = "SKU销售价必须大于等于0")
		@DecimalMax(value = "99999999.99", message = "SKU销售价必须小于等于99999999.99")
		private BigDecimal price;

		@Min(value = 0, message = "SKU库存必须大于等于0")
		@ApiModelProperty(value = "SKU库存")
		private Integer stocks;

		@NotNull(message = "商品编码不能为空")
		@ApiModelProperty(value = "商品编码")
		private String partyCode;
	}


	@Data
	@Builder
	@ApiModel("属性")
	@NoArgsConstructor
	@AllArgsConstructor
	public static class Attr implements Serializable {

		private static final long serialVersionUID = -543210987654321L;

		@ApiModelProperty("属性名")
		@NotNull(message = "属性名不能为空")
		private String name;

		@ApiModelProperty("属性值")
		@NotNull(message = "属性值不能为空")
		private String value;

	}

	@Override
	public String getApiPath() {
		return ApiPathConstantsV4.SAVE_PROD_V4;
	}
}
